<?php

//UMA new
namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ZipResource extends JsonResource
{
    /**
     * 把 model 转换成 array.
     * model 変換 array
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'prefcode' => $this->Precode,
            'citycode' => $this->zip_cd,
            'pref' => $this->pref,
            'city' => $this->city,
            'town' => $this->where('zip7', $this->zip7)->count() > 1 ?'' : $this->town,
        ];
    }
}
